<style scoped>
#app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
}
.layout {
    border: 1px solid #d7dde4;
    background: #f5f7f9;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
}
.layout-header-bar {
    background: #fff;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}
.layout-logo-left {
    width: 90%;
    height: 30px;
    background: #5b6270;
    border-radius: 3px;
    margin: 15px auto;
}
.menu-icon {
    transition: all 0.3s;
}
.rotate-icon {
    transform: rotate(-90deg);
}
.menu-item span {
    display: inline-block;
    overflow: hidden;
    width: 69px;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    transition: width 0.2s ease 0.2s;
}
.menu-item i {
    transform: translateX(0px);
    transition: font-size 0.2s ease, transform 0.2s ease;
    vertical-align: middle;
    font-size: 16px;
}
.collapsed-menu span {
    width: 0px;
    transition: width 0.2s ease;
}
.collapsed-menu i {
    transform: translateX(5px);
    transition: font-size 0.2s ease 0.2s, transform 0.2s ease 0.2s;
    vertical-align: middle;
    font-size: 22px;
}
</style>
<template>
  <div class="layout">
        <Layout>
            <Sider ref="side1" hide-trigger collapsible :collapsed-width="78" v-model="isCollapsed">
                <Menu active-name="1-1" theme="dark" width="auto" :class="menuitemClasses">
                    <MenuItem name="1-1" @click.native="showHome()">
                        <Icon type="ios-navigate"></Icon>
                        <span>Option 1</span>
                    </MenuItem>
                    <MenuItem name="1-2" @click.native="showVideoManager()">
                        <Icon type="search"></Icon>
                        <span>Option 2</span>
                    </MenuItem>
                    <MenuItem name="1-3" >
                        <Icon type="settings"></Icon>
                        <span>Option 3</span>
                    </MenuItem>
                </Menu>
            </Sider>
            <Layout>
                <Header :style="{padding: 0}" class="layout-header-bar">
                    <Icon @click.native="collapsedSider" :class="rotateIcon" :style="{margin: '20px 20px 0'}" type="navicon-round" size="24"></Icon>
                    <Button style="float:right; margin-top:15px;margin-right:15px" @click="logout()">退出</Button>
                    <div style="float:right; margin-right:15px">你好  {{$route.params.user.username}}</div>
                </Header>
                <Content :style="{margin: '20px', background: '#fff', minHeight: '600px'}">
                    <router-view></router-view>
                </Content>
            </Layout>
        </Layout>
    </div>
  <!-- <div id="app">
    <img src="./assets/logo.png">
    <router-view/>
  </div> -->
</template>

<script>
export default {
    name: 'App',
    data() {
        return {
            isCollapsed: false
        }
    },
    computed: {
        rotateIcon() {
            return ['menu-icon', this.isCollapsed ? 'rotate-icon' : '']
        },
        menuitemClasses() {
            return ['menu-item', this.isCollapsed ? 'collapsed-menu' : '']
        }
    },
    methods: {
        collapsedSider() {
            this.$refs.side1.toggleCollapse()
        },
        showVideoManager() {
            console.log('showVideoManager')
            //   this.$router.push({name: 'VideoManager', params:{user: this.$route.params.user}})
            this.startComponent('VideoManager')
        },
        showHome() {
            console.log('showHome')
            //   this.$router.push({name: 'Home'})
            this.startComponent('Home')
        },
        startComponent(name) {
            this.$router.push({
                name: name,
                params: { user: this.$route.params.user }
            })
        },
        async logout() {
            console.log('logout')
            const response = await this.$axios.post(
                '/meiju-boss/api/v1/auth/logout'
            )
            if (response.data.success) {
                this.$router.replace('/login')
            } else {
                console.log('退出失败')
                this.$Message.error('退出失败')
            }
        }
    },
    mounted() {
        console.log('mounted params:', this.$route.params)
    }
}
</script>
